export default class ActorV extends Laya.Script{

    gId=0

    
    spr:Laya.Sprite
    flipPoint:Laya.Sprite
    img:Laya.Image
    label_atk:Laya.Label
    label_hp:Laya.Label

    isKickingOut=false
    speedX=0
    speedY=0
    onAwake(): void {
        this.spr=this.owner as Laya.Sprite
        this.flipPoint=this.spr.getChildByName('flipPoint') as Laya.Sprite
        this.img=this.flipPoint.getChildByName('img') as Laya.Image
        this.label_atk=this.spr.getChildByName('label_atk') as Laya.Label
        this.label_hp=this.spr.getChildByName('label_hp') as Laya.Label

        
    }

    setAtk(value:number){
        this.label_atk.text=String(value)
    }
    setHp(value:number){
        this.label_hp.text=String(value)
    }
    setFlip(flip:boolean){
        if(flip){
            this.flipPoint.scaleX=-1
        }else{
            this.flipPoint.scaleX=1
        }
    }
    get x(){
        return this.spr.x
    }
    get y(){
        return this.spr.y
    }
    set x(v){
        this.spr.x=v
    }
    set y(v){
        this.spr.y=v
    }

    die(){
        Laya.Tween.to(this.img,{alpha:0},400,null,Laya.Handler.create(this,()=>{
            this.spr.destroy()
        }))
    }
    kickOut(dir:1|-1){
        this.isKickingOut=true
        this.speedY=-3
        this.speedX=3*dir
        
    }

    onUpdate(): void {
        if(this.isKickingOut){
            this.x+=this.speedX
            this.y+=this.speedY
            this.speedY+=0.1

            if(this.x<0 || this.x>Laya.stage.width || this.y<0 || this.y>Laya.stage.height){
                this.isKickingOut=false
                this.die()
            }
        }
    }
}